package com.lxmes.base.service.impl;

import java.util.List;

import com.lxmes.common.exception.ServiceException;
import com.lxmes.common.utils.DateUtils;
import com.lxmes.common.utils.SecurityUtils;
import com.lxmes.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lxmes.base.mapper.JcIteminfoClassMapper;
import com.lxmes.base.domain.JcIteminfoClass;
import com.lxmes.base.service.IJcIteminfoClassService;

/**
 * 物料大类Service业务层处理
 * 
 * @author 王超
 * @date 2022-06-11
 */
@Service
public class JcIteminfoClassServiceImpl implements IJcIteminfoClassService 
{
    @Autowired
    private JcIteminfoClassMapper jcIteminfoClassMapper;

    /**
     * 查询物料大类
     * 
     * @param id 物料大类主键
     * @return 物料大类
     */
    @Override
    public JcIteminfoClass selectJcIteminfoClassById(Long id)
    {
        return jcIteminfoClassMapper.selectJcIteminfoClassById(id);
    }

    /**
     * 查询物料大类列表
     * 
     * @param jcIteminfoClass 物料大类
     * @return 物料大类
     */
    @Override
    public List<JcIteminfoClass> selectJcIteminfoClassList(JcIteminfoClass jcIteminfoClass)
    {
        jcIteminfoClass.setFactoryCode(SecurityUtils.getFactoryCode());
        return jcIteminfoClassMapper.selectJcIteminfoClassList(jcIteminfoClass);
    }

    /**
     * 新增物料大类
     * 
     * @param jcIteminfoClass 物料大类
     * @return 结果
     */
    @Override
    public int insertJcIteminfoClass(JcIteminfoClass jcIteminfoClass)
    {
        jcIteminfoClass.setFactoryCode(SecurityUtils.getFactoryCode());
        jcIteminfoClass.setFactoryName(SecurityUtils.getFactoryName());
        jcIteminfoClass.setCreateTime(DateUtils.getNowDate());
        jcIteminfoClass.setDeptId(SecurityUtils.getDeptId());
        JcIteminfoClass aClass = jcIteminfoClassMapper.selectJcIteminfoClassByCode(jcIteminfoClass.getClassId());
        if(!StringUtils.isNull(aClass)){
            throw new ServiceException("物料类型编码重复！");
        }
        return jcIteminfoClassMapper.insertJcIteminfoClass(jcIteminfoClass);
    }

    /**
     * 修改物料大类
     * 
     * @param jcIteminfoClass 物料大类
     * @return 结果
     */
    @Override
    public int updateJcIteminfoClass(JcIteminfoClass jcIteminfoClass)
    {
        jcIteminfoClass.setUpdateTime(DateUtils.getNowDate());
        return jcIteminfoClassMapper.updateJcIteminfoClass(jcIteminfoClass);
    }

    /**
     * 批量删除物料大类
     * 
     * @param ids 需要删除的物料大类主键
     * @return 结果
     */
    @Override
    public int deleteJcIteminfoClassByIds(Long[] ids)
    {
        return jcIteminfoClassMapper.deleteJcIteminfoClassByIds(ids);
    }

    /**
     * 删除物料大类信息
     * 
     * @param id 物料大类主键
     * @return 结果
     */
    @Override
    public int deleteJcIteminfoClassById(Long id)
    {
        return jcIteminfoClassMapper.deleteJcIteminfoClassById(id);
    }
}
